package com.iurac.sys.permission;

import com.iurac.domain.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdminInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute("userInfo");
        String role = user.getRole();
        if("管理员".equals(role) || "超级管理员".equals(role)){
            return true;
        }else {
            response.sendRedirect(request.getContextPath()+"/404.jsp");
        }
        return false;
    }
}
